import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * @author: xinmi
 * @date: 2020/10/29
 * @description:
 */
public class Gps {
    public static void main(String[] args) throws ParseException {
        Calendar cal = Calendar.getInstance();
        Date now =  new Date( );
        cal.setTime(now);

        int month = cal.get(Calendar.MONTH);
        int year = cal.get(Calendar.YEAR);

        System.out.println("month = " + month + " year " + year);

        String str = "2007-1-18";
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");

        Date date = null;
        try {
            date = format1.parse(str);

        } catch (ParseException e) {
             e.printStackTrace();
        }

        cal.setTime(date);

        month = cal.get(Calendar.MONTH);
        year = cal.get(Calendar.YEAR);

        System.out.println("month = " + month + " year " + year);

        LocalDate today = LocalDate.now();
        System.out.println("hi " + today.toString());

        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        System.out.println("month = " + today.getMonthValue() + " year " + today.getYear());
        String dateStr = today.format(fmt);
        System.out.println(dateStr);

        String str2 = "2019-03-03";
        //指定转换格式
        DateTimeFormatter fmt2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        //进行转换
        LocalDate date2 = LocalDate.parse(str2, fmt2);

        System.out.println("month = " + date2.getMonthValue() + " year " + date2.getYear());

        String tt = "0000-00-00 00:15:49";
        DateFormat formatt1 = new SimpleDateFormat("mm:ss");
        DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date datet = format2.parse(tt);
        System.out.println(datet);



    }

    private static double EARTH_RADIUS = 6378.137;
    private static double rad(double d)
    {
        return d * Math.PI / 180.0;
    }
    public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
    {
        double radLat1 = rad(lat1);
        double radLat2 = rad(lat2);
        double a = radLat1 - radLat2;
        double b = rad(lng1) - rad(lng2);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
                Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        return s;
    }
}
